#ifndef __INCobjbaseh
#define __INCobjbaseh
#include <atomic>
#include <mutex>
#include <type.h>
#include <table.h>
#include <cliArg.h>
#include <declarecClass.h>
#include <log.h>

using ArgList = cli::Args;

class objbase
{
private:
    DISABLE_COPY_CLASS(objbase);

public:
    DECLARE_CTOR_DTOR(objbase);
    virtual STATUS dump(TextTable& t) = 0;
    virtual STATUS process(int sendId, int recvId, int cmdId, ArgList& reqArgs, TextTable& outMsg) = 0;
    virtual STATUS preInit() = 0;
    virtual STATUS postInit() = 0;
    virtual STATUS destory() = 0;

public:
    mutable std::mutex  m_objectLock;
};

#define PROCESS_DESC(procFunc)                                 \
    virtual STATUS procFunc(int sendId, int recvId, int cmdId, \
                            ArgList &reqArgs, TextTable &outMsg)

#define PROCESS_IMPL_DESC(cls, procFunc)                    \
    STATUS cls::procFunc(int sendId, int recvId, int cmdId, \
                         ArgList &reqArgs, TextTable &outMsg)

#define PROCESS_BEGIN()                                             \
    LOG_TRACE("Receive Command: sendId(%#x) recvId(%#x) cmdId(%#x)",\
                sendId, recvId, cmdId);                             \
    STATUS __retVal = OK;                                           \
    switch (cmdId)                                                  \
    {

#define PROCESS_CALL(cmd, func)                                    \
    case cmd:                                                      \
        __retVal = (func)(sendId, recvId, cmdId, reqArgs, outMsg); \
        break;

#define PROCESS_END(_retVal)  \
    default:                  \
        __retVal = (_retVal); \
        break;                \
        }                     \
        return __retVal;

#define OBJBASE_EXTERN_MEMBER_IMPL()           \
    PROCESS_DESC(process) override;            \
    virtual STATUS dump(TextTable &) override; \
    virtual STATUS preInit() override;         \
    virtual STATUS postInit() override;        \
    virtual STATUS destory() override;

#endif
